<template>
  <div class="wrap">
    <div class="wrap-button">
      <a-button style="margin-right: 8px" type="primary" @click="showAddRole">新增</a-button>
      <a-button style="margin-right: 8px" type="primary" @click="showAddRole">导出</a-button>
      <div style="float: right">
        <a-select
          ref="select"
          v-model:value="value1"
          style="width: 120px; margin-right: 8px"
          @focus="focus"
          @change="handleChange"
          placeholder="客户"
        >
          <a-select-option value="jack">Jack</a-select-option>
          <a-select-option value="lucy">Lucy</a-select-option>
          <a-select-option value="disabled" disabled>Disabled</a-select-option>
          <a-select-option value="Yiminghe">yiminghe</a-select-option>
        </a-select>
        <a-input
          v-model:value="keyword"
          style="width: 180px; margin-right: 8px"
          placeholder="输入单据关键字查询"
          allow-clear
        >
          <template #prefix>
            <SearchOutlined style="color: #666" />
          </template>
        </a-input>

        <a-button type="primary" @click="handleSearch">查询</a-button>
      </div>
    </div>
    <div class="wrap-table">
      <!-- <BaseTitle title="用户列表" /> -->
      <a-table
        :loading="loading"
        :dataSource="data"
        :columns="columns"
        size="middle"
        @change="handleTableChange"
        width="300"
      />
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { ref, computed, reactive, onMounted } from 'vue'
  import { pageScrap } from '/@/api/asset'
  import { AssetVO, AssetSO } from '/@/api/asset/model/assetModel'
  const loading = ref(false)

  const columns = [
    {
      title: '资产名称',
      dataIndex: 'assetName',
      key: 'assetName',
      align: 'center',
    },
    {
      title: '资产EPC',
      dataIndex: 'epc',
      key: 'epc',
      align: 'center',
    },
    {
      title: '客户名称',
      dataIndex: 'clientName',
      fixed: 'clientName',
      align: 'center',
    },
    {
      title: '客户描述',
      dataIndex: 'description',
      key: 'description',
      align: 'center',
    },
    {
      title: '位置',
      dataIndex: 'position',
      key: 'position',
      align: 'center',
    },
    {
      title: '入库时间',
      dataIndex: 'createTime',
      key: 'createTime',
      align: 'center',
    },
    {
      title: '报废时间',
      dataIndex: 'scrapTime',
      key: 'scrapTime',
      align: 'center',
    }
  ]

  let data = ref<AssetVO[]>([])

const pagination = ref({
  total: 0,
  current: 1,
  pageSize: 15,
  size: '',
  showSizeChanger: false,
  showQuickJumper: false,
})
const pageParam = computed(() => ({
  query: recordSo,
  current: pagination.value?.current,
  size: pagination.value?.pageSize,
}))
let recordSo = reactive<AssetSO>({
  clientId: '',
  assetStatus: -1,
  keyword: '',
})

onMounted(() => {
  list()
})

async function list() {
  loading.value = true
  const res = await pageScrap(pageParam.value)
  console.log('res', res)
  data.value = res.records
  pagination.value.total = Number(res.total)
  pagination.value.current = Number(res.current)
  loading.value = false
}

function handleTableChange(page) {
  pagination.value.current = page.current
  list()
}
</script>
<style lang="scss" scoped>
  .wrap {
    &-table {
      margin-top: 16px;
    }
  }
</style>
